/*    */ package com.wzh.action.tag;
/*    */ 
/*    */ import com.wzh.bean.QueryResult;
/*    */ import com.wzh.bean.links.FriendLink;
/*    */ import com.wzh.service.links.FlinkService;
/*    */ import java.util.Iterator;
/*    */ import java.util.LinkedHashMap;
/*    */ import java.util.List;
/*    */ import javax.servlet.ServletResponse;
/*    */ import javax.servlet.jsp.JspException;
/*    */ import javax.servlet.jsp.PageContext;
/*    */ import javax.servlet.jsp.tagext.TagSupport;
/*    */ import org.apache.struts2.ServletActionContext;
/*    */ import org.springframework.web.context.WebApplicationContext;
/*    */ import org.springframework.web.context.support.WebApplicationContextUtils;
/*    */ 
/*    */ public class FlinkTag extends TagSupport
/*    */ {
/*    */   private static final long serialVersionUID = 1L;
/* 21 */   private int num = 30;
/*    */   private String order;
/*    */   private String var;
/*    */   private Iterator<FriendLink> it;
/*    */ 
/*    */   public int getNum()
/*    */   {
/* 29 */     return this.num;
/*    */   }
/*    */   public void setNum(int num) {
/* 32 */     this.num = num;
/*    */   }
/*    */   public String getOrder() {
/* 35 */     return this.order;
/*    */   }
/*    */   public void setOrder(String order) {
/* 38 */     this.order = order;
/*    */   }
/*    */   public String getVar() {
/* 41 */     return this.var;
/*    */   }
/*    */   public void setVar(String var) {
/* 44 */     this.var = var;
/*    */   }
/*    */ 
/*    */   private void init() {
/* 48 */     WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());
/* 49 */     FlinkService flinkService = (FlinkService)wac.getBean("flinkServiceBean");
/*    */ 
/* 53 */     LinkedHashMap orderby = new LinkedHashMap();
/* 54 */     if ((this.order != null) && (!"".equals(this.order))) {
/* 55 */       String[] orderStr = this.order.split("\\s+");
/* 56 */       orderby.put(orderStr[0], orderStr[1]);
/*    */     }
/*    */ 
/* 59 */     QueryResult qr = flinkService.getScrollData(0, this.num, orderby);
/* 60 */     List flinks = qr.getResultlist();
/*    */ 
/* 62 */     if (flinks != null)
/* 63 */       this.it = flinks.iterator();
/*    */   }
/*    */ 
/*    */   public int doStartTag()
/*    */     throws JspException
/*    */   {
/* 72 */     init();
/*    */ 
/* 75 */     this.pageContext.getResponse().setCharacterEncoding("utf-8");
/* 76 */     if ((this.it != null) && (this.it.hasNext())) {
/* 77 */       this.pageContext.setAttribute(this.var, this.it.next());
/* 78 */       return 1;
/*    */     }
/* 80 */     return 0;
/*    */   }
/*    */ 
/*    */   public int doAfterBody()
/*    */     throws JspException
/*    */   {
/* 86 */     if ((this.it != null) && (this.it.hasNext())) {
/* 87 */       this.pageContext.setAttribute(this.var, this.it.next());
/* 88 */       return 2;
/*    */     }
/* 90 */     return 0;
/*    */   }
/*    */ 
/*    */   public int doEndTag()
/*    */     throws JspException
/*    */   {
/* 97 */     this.pageContext.removeAttribute(this.var);
/* 98 */     return 6;
/*    */   }
/*    */ }

/* Location:           C:\work\apache-tomcat-7.0.55\webapps\ROOT\WEB-INF\classes\
 * Qualified Name:     com.wzh.action.tag.FlinkTag
 * JD-Core Version:    0.6.1
 */